﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using caedisi.Web.DataModel;
using caedisi.Models;
using caedisi.Helpers;
using System.Windows.Data;

namespace caedisi.Views.Controls
{
    /// <summary>
    /// 
    /// </summary>
    public partial class TransitionRuleValidationError : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TransitionRuleControl"/> class.
        /// </summary>
        public TransitionRuleValidationError()
        {
            InitializeComponent();            
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TransitionRuleControl"/> class.
        /// </summary>
        /// <param name="ruleValidationError">The transition rule.</param>
        public TransitionRuleValidationError(RuleValidationError ruleValidationError)
        {
            InitializeComponent();
            this.CurrentTransitionRuleValidationError = ruleValidationError;
        }

        /// <summary>
        /// Gets or sets the current transition rule.
        /// </summary>
        /// <value>
        /// The current transition rule.
        /// </value>
        public RuleValidationError CurrentTransitionRuleValidationError
        {
            get { return (RuleValidationError)GetValue(CurrentTransitionRuleValidationErrorProperty); }
            set
            {
                SetValue(CurrentTransitionRuleValidationErrorProperty, value);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public static readonly DependencyProperty CurrentTransitionRuleValidationErrorProperty =
                DependencyProperty.Register(
                "CurrentTransitionRuleValidationError",
                typeof(RuleValidationError),
                typeof(TransitionRuleValidationError), 
                new PropertyMetadata(OnCurrentEntityChanged));


        /// <summary>
        /// Called when [current entity changed].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void OnCurrentEntityChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            RuleValidationError transitionRuleValidationError = args.NewValue as RuleValidationError;
            TransitionRuleValidationError transitionRuleValidationErrorControl = sender as TransitionRuleValidationError;

            transitionRuleValidationErrorControl.transitionRuleControl1.DataContext = transitionRuleValidationError.Item1;
            transitionRuleValidationErrorControl.transitionRuleControl2.DataContext = transitionRuleValidationError.Item2;
            
            transitionRuleValidationErrorControl.transitionRuleControl1.CurrentTransitionRule = transitionRuleValidationError.Item1;
            transitionRuleValidationErrorControl.transitionRuleControl2.CurrentTransitionRule = transitionRuleValidationError.Item2;
             
        }
    }
}
